import { doRecordsList, doRelatedQuestion, doChatRecords, doExportAnswerRecords } from '@/services/datastatistics';
import { doRobotList } from '@/services/robotManagement';
export default {
  namespace: 'answerRecordsList',

  state: {
    list: [],
    suggestList: [],
    qaList: [],
  },

  effects: {
    *fetchRobotList({ payload, callback }, { call, put }) {
      const response = yield call(doRobotList, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchRecordsList({ payload, callback }, { call, put }) {
      const response = yield call(doRecordsList, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *relatedQuestion({ payload, callback }, { call, put }) {
      const response = yield call(doRelatedQuestion, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchChatRecords({ payload, callback }, { call, put }) {
      const response = yield call(doChatRecords, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *exportAnswerRecords({ payload, callback }, { call, put }) {
      const response = yield call(doExportAnswerRecords, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    fetchb(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    fetchc(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    fetchd(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        list: [],
        suggestList: [],
        qaList: [],
      };
    },
  },
};
